<?php
/**
*
* 功能描述（生产控制器）
*
* @author suoya <jlusuoya@gmail.com>
* @version 1
*/

class CtrlProd extends CtrlBase
{
	public $paramCheck = array(
		"showlist" => array(
			'status' => array("GET", "0", "intval", "notnegative"),
			'd_start' => array('GET', '', '', 'datetime'),
			'd_end' => array('GET', '', '', 'datetime'),
			'key' => array("GET", "", "trim", ""),
			'keyword' => array("GET", "", "trim", ""),
			"page" => array("GET", "1", "intval", "positive"),
		),
		"setstatus" => array(
			'id' => array("GET", "must", "intval", "positive"),
			'status' => array("GET", "must", "intval", "positive"),
		),
		"take" => array(
			'id' => array("GET", "must", "intval", "positive"),
			'man' => array("GET", "must", "trim", "notempty"),
		),
		"remove" => array(
			'id' => array("GET", "must", "intval", "positive"),
		),
		"detail" => array(
			'id' => array("GET", "must", "intval", "positive"),
		),
		"noticedely" => array(
			'id' => array("GET", "must", "intval", "positive"),
		),
	);

	public $perm = array('prod', "index.php?action=login.tologin");

	function ShowList()
	{
		$status = $this->params['status'];
		$key = $this->params['key'];
		$keyword = $this->params['keyword'];
		$d_start = $this->params['d_start'];
		$d_end = $this->params['d_end'];
		$obj = $this->GetModel("prod");
		$data = $obj->GetList($this->params['page'], $status, SlotFormt('beg', $d_start), SlotFormt('end', $d_end), $key, $keyword);
		$this->assign("listdata", $data['data']);
		$this->assign("totalCnt", $data['cnt']);
		$this->assign("pageCnt", $data['pageCnt']);
		$this->assign("curPage", $this->params['page']);
		$this->assign("status", $status);
		$this->assign("key", $key);
		$this->assign("keyword", $keyword);
		$this->assign("d_start", $d_start);
		$this->assign("d_end", $d_end);
		return RT_TPL;
	}

	function SetStatus()
	{
		$id = $this->params['id'];
		$sta = $this->params['status'];
		$data = array('status' => $sta);
		switch($sta)
		{
		case 1:
			$data['prod_adm'] = 0;
			break;
		case 2:
		case 3:
			$data['prod_adm'] = $this->user->userid;
			$data['finishtime'] = date('Y-m-d H:i:s');
			break;
		default:
			echo "1";
			return RT_NONE;
		}
		$obj = $this->GetModel("prod");
		$cnt = $obj->Update($data, $id);
		if($cnt == 0)
			echo "2";
		else
		{
			$this->CoreLog('prod_sta', $id, $sta, '');
			echo "0";
		}
		return RT_NONE;
	}

	function Detail()
	{
		$obj = $this->GetModel("prod");
		$id = $this->params['id'];
		$data = $obj->GetAllInfo($id);
		if(!$data)
		{
			$this->assign("msg", "订单不存在");
			return RT_MSG;
		}
		$this->assign("data", $data);
		$goods = $obj->GetAllGoods($id);
		$this->assign("goods", $goods);
		return RT_TPL;

	}

	function Take()
	{
		$obj = $this->GetModel("prod");
		$id = $this->params['id'];
		$man = $this->params['man'];
		$data = array(
			'takeman' => $man,
			'taketime' => date('Y-m-d H:i:s'),
			'status' => 4,
		);
		$cnt = $obj->Update($data, $id);
		if($cnt <= 0)
			echo "2";
		else
		{
			echo "0";
			$this->CoreLog('prod_take', $id, $cnt, $man);
		}
		return RT_NONE;
	}

	function Remove()
	{
		$obj = $this->GetModel("prod");
		$id = $this->params['id'];
		$cnt = $obj->Remove($id);
		if($cnt <= 0)
			echo "2";
		else
		{
			echo "0";
			$this->CoreLog('prod_del', $id, $cnt, '');
		}
		return RT_NONE;
	}

	function NoticeDely()
	{
		$obj = $this->GetModel("prod");
		$id = $this->params['id'];
		$rid = $obj->NoticeDely($id);
		if($rid <= 0)
			echo "2";
		else
		{
			echo "0";
			$this->CoreLog('prod_dely', $id, $rid, '');
		}
		return RT_NONE;
	}
}

